#region

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Vin.Extension.Framework.Aop;
using Vin.Extension.Framework.Base;
using Vin.Extension.Framework.Constants;
using Vin.Extension.Framework.Monitor.Filters;
using Vin.Extension.Framework.Upload.Options;
using Vin.Extension.Framework.Upload.ServiceInterface;
using Vin.Extension.JwtBearer.Attributes;
using Vin.Tool.AspNetCore.Singleton;
using Vin.Tool.Attributes;

#endregion

namespace Vin.Extension.Framework.Upload.Controller.Controllers;

[Route("/upload")]
public class UploadController : VinFrameworkBaseController
{
    private readonly IUploadService _uploadService;

    public UploadController(IOptionsMonitor<UploadOption> uploadOption)
    {
        _uploadService =
            VinApp.GetRequiredKeyServiceByHttpContext<IUploadService>(uploadOption.CurrentValue.ServiceKey);
    }

    [VinJwtIsAuthorize, OperateLog("文件上传", VinBusinessType.Upload), HttpPost("file")]
    public async Task<IActionResult> File(IFormFile file, [FromForm] string? dir)
    {
        return Success(await _uploadService.UploadFileAsync(file, dir));
    }
}